import sys, os, pathlib


_m_project_name = "pybi-gallery"


def _find_src(cur_dir: pathlib.Path):

    while 1:
        cur_dir = cur_dir.parent

        if cur_dir == cur_dir.parent:
            raise Exception(f"找不到目录 {_m_project_name}")

        if cur_dir.name == _m_project_name:
            return cur_dir


def reset_paths(source_file_path: str):
    os.chdir(pathlib.Path(source_file_path).parent.absolute())
    sys.path.insert(0, str(_find_src(pathlib.Path(source_file_path))))
